<template>
  <fe-page title="表单详情" @back="goBack">
    <template #extra>
      <el-button type="primary" icon="Edit" :loading="loading" @click="handleUpdate" v-hasPermi="['service:form:edit']">编辑</el-button>
		</template>
    <preview-form :formConf="previewData.formConf" :drawingList="previewData.drawingList" type="preview" v-loading="loading"></preview-form>
  </fe-page>
</template>
<script setup name="FormView">
import previewForm from './build/index'
import { getData } from "@/api/service/process"

const route = useRoute()
const { proxy } = getCurrentInstance()

const id = route.params && route.params.id
const loading = ref(true)
const form = ref({})
const previewData = ref({
  formConf: {formRef: 'formRef'},
  drawingList: []
})

function getInfo() {
	loading.value = true
	getData(id).then(response => {
		loading.value = false
		let result = response.result || ''
    form.value = result
    let content = JSON.parse(result)
    previewData.value = {
      formConf: content.formParams,
      drawingList: content.drawingParams
    }
  })
}

function handleUpdate() {
  const obj = { path: "/service/form-data/edit/" + id, query: { t: Date.now(), current: route.query.current }}
  proxy.$tab.closeOpenPage(obj)
}

function goBack() {
  const obj = { path: "/service/form",  query: { t: Date.now(), current: route.query.current }}
  proxy.$tab.closeOpenPage(obj)
}

getInfo()
</script>